using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace DanielSig
{
	public static class XCollection
	{	
		public static String ToArrayString<T>(this ICollection<T> arr, Func<T, String> predicate)
		{
			return arr.ToArrayString(predicate, ",", "[", "]");
		}
		public static String ToArrayString<T>(this ICollection<T> arr, Func<T, String> predicate, String separator)
		{
			return arr.ToArrayString(predicate, separator, "[", "]");
		}
		public static String ToArrayString<T>(this ICollection<T> arr, Func<T, String> predicate, String separator, String start, String end)
		{
			if(arr != null)
			{
				StringBuilder builder = new StringBuilder(start, arr.Count * 5);
				foreach (T item in arr)
				{
					builder.Append((predicate(item) ?? "null") + separator);
				}
				if(builder.Length > separator.Length)
				{
					builder.Length -= separator.Length;
				}
				builder.Append(end);
				return builder.ToString();
			}
			return "null";
		}
		public static String ToArrayString<T>(this ICollection<T> arr)
		{
			return arr.ToArrayString(",", "[", "]");
		}
		public static String ToArrayString<T>(this ICollection<T> arr, String separator)
		{
			return arr.ToArrayString(separator, "[", "]");
		}
		public static String ToArrayString<T>(this ICollection<T> arr, String separator, String start, String end)
		{
			return arr.ToArrayString(x => x.ToString(), separator, start, end);
		}
	}
}

